<?php

namespace app\api\model\dealer;

use app\api\model\User;
use app\common\model\dealer\Bank as BankModel;

/**
 * 用户银行卡模型
 * Class Apply
 * @package app\api\model\dealer
 */
class Bank extends BankModel
{
    /**
     * 隐藏字段
     * @var array
     */
    protected $hidden = [
        'create_time',
        'update_time',
    ];

    /**
     * @param $user_id
     * @return false|static[]
     * @throws \think\exception\DbException
     */
    public function getList($user_id)
    {
        return self::all(compact('user_id'));
    }

    /**
     * 新增银行卡
     * @param User $user
     * @param $data
     * @param $wxapp_id
     * @return mixed
     */
    public function add($user, $data, $wxapp_id)
    {
        return $this->transaction(function () use ($user, $data, $wxapp_id) {
            // 添加
            $this->allowField(true)->save([
                'user_id' => $user['user_id'],
                'bank_card' => $data['bank_card'],
                'bank_account' => $data['bank_account'],
                'bank_name' => $data['bank_name'],
                'wxapp_id' => $wxapp_id,
                'create_time' => time(),
                'update_time' => time(),
            ]);
            return true;
        });
    }

}